package com.sddz.pacs.controller;

import com.sddz.pacs.annotation.SysLogger;
import com.sddz.pacs.dto.JsonResult;
import com.sddz.pacs.entity.SysUser;
import com.sddz.pacs.service.SysUserRoleService;
import com.sddz.pacs.support.ResultConstant;
import com.sddz.pacs.util.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by zhangjinghang.
 * DateTime 2018/5/24 15:59
 */
@RestController
@RequestMapping("/sysUserRole")
@Api(description = "用户角色管理")
public class  SysUserRoleController {
    @Autowired
    private SysUserRoleService sysUserRoleService;

    @PostMapping("/update")
    @SysLogger(value = "新增用户角色",type = "用户角色管理")
    @ApiOperation(value="新增系统用户")
    @ApiImplicitParam(name = "sysUser",value = "用户角色json对象",required = true)
    public JsonResult update(@RequestBody SysUser sysUser){
        //1.校验数据完整性
        ValidatorUtils.validateEntity(sysUser);
        boolean flag = sysUserRoleService.updateUserRole(sysUser);

        if(!flag){
            return JsonResult.failure(ResultConstant.UPDATE_FAILURE);
        }
        return JsonResult.success(ResultConstant.UPDATE_SUCCESS);
    }
}
